package leetcode;

import java.util.LinkedList;
import java.util.Queue;

public class MaxDepth {
    public int dfs(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int left = dfs(root.left);
        int right = dfs(root.right);
        return Math.max(left, right) + 1;
    }

    public int bfs(TreeNode root) {
        if (root == null) {
            return 0;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        int ans = 0;
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                TreeNode head_e = queue.remove();
                if (head_e.left != null) {
                    queue.add(head_e.left);
                }
                if (head_e.right != null) {
                    queue.add(head_e.right);
                }
            }
            ans++;
        }
        return ans;
    }
}
